<?php
/**
 *  菜单管理
*/

namespace app\admin\controller;

use app\common\exception\BaseException;
use app\admin\service\Menu as ServiceMenu;
use app\facade\Basic;
use think\Request;

class Menu extends BaseController
{

    /**
     *  权限菜单
    */
    public function RoleMenu(Request $request)
    {

        $param['creator'] = $request->operator_id;
        $param['roles'] = $request->operator_roles;
        $param['isadmin'] = $request->isadmin;

        /* 验证 */
        //$this->validateData($param,'Menu.list');

        /* 创建列表 */
        $ServiceMenu = new ServiceMenu();
        $result = $ServiceMenu->RoleMenu($param);
        return Basic::json($result);
    }


    /**
     *  菜单列表
     */
    public function index(Request $request)
    {
        $param['creator'] = $request->operator_id;
        /* 验证 */
        //$this->validateData($param,'Menu.list');

        /* 创建列表 */
        $ServiceMenu = new ServiceMenu();
        $result = $ServiceMenu->list($param);
        return Basic::json($result);
    }

    /**
     *  详情
    */
    public function detail(Request $request)
    {

        $param['creator'] = $request->operator_id;
        $param['id'] = $request->param('id',null);

        /* 验证 */
        //$this->validateData($param,'Menu.list');

        /* 创建列表 */
        $ServiceMenu = new ServiceMenu();
        $result = $ServiceMenu->detail($param);
        return Basic::json($result);
    }

    /**
     *
     *  添加菜单
    */
    public function create(Request $request)
    {
        $param['creator'] = $request->operator_id;
        $param['parent_id'] = $request->param('parent_id',0);  // 父ID
        $param['type'] = $request->param('type',null);  // 类型 1-目录 2-菜单
        $param['name'] = $request->param('name',null);  // 名称
        $param['components'] = $request->param('components',null);
        $param['components_name'] = $request->param('components_name',null);
        $param['icon'] = $request->param('icon',null);
        $param['url'] = $request->param('url',null);
        $param['redirect'] = $request->param('redirect',"");
        $param['active_menu'] = $request->param('active_menu',1);
        $param['status'] = $request->param('status',1);
        $param['is_hide'] = $request->param('is_hide',1);
        $param['is_display'] = $request->param('is_display',0);
        $param['is_multiple'] = $request->param('is_multiple',0);
        $param['is_alive'] = $request->param('is_alive',0);
        $param['sort'] = $request->param('sort',0);

        $param['permission'] = $request->param('permission',null);

        /* 验证 */
      // $this->validateData($param,'Menu.create');

        /* 创建菜单 */
        $ServiceMenu = new ServiceMenu();
        $result = $ServiceMenu->save($param);
        return Basic::json($result);
    }

    /**
     *  更新修改菜单
    */
    public function update(Request $request)
    {
        $param['creator'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        $param['parent_id'] = $request->param('parent_id',null);  // 父ID
        $param['type'] = $request->param('type',null);  // 类型 1-目录 2-菜单
        $param['name'] = $request->param('name',null);  // 名称
        $param['components'] = $request->param('components',null);
        $param['components_name'] = $request->param('components_name',null);
        $param['icon'] = $request->param('icon',null);
        $param['url'] = $request->param('url',null);
        $param['redirect'] = $request->param('redirect',"");
        $param['active_menu'] = $request->param('active_menu',1);
        $param['status'] = $request->param('status',1);
        $param['is_hide'] = $request->param('is_hide',1);
        $param['is_display'] = $request->param('is_display',0);
        $param['is_multiple'] = $request->param('is_multiple',0);
        $param['is_alive'] = $request->param('is_alive',0);
        $param['sort'] = $request->param('sort',0);

        /* 验证 */
        // $this->validateData($param,'Menu.create');

        /* 创建菜单 */
        $ServiceLogin = new ServiceMenu();
        $result = $ServiceLogin->save($param);
        return Basic::json($result);
    }


    /**
     *  菜单状态修改
    */
    public function status(Request $request)
    {
        $param['creator'] = $request->operator_id;
        $param['ids'] = $request->param('ids',0);
        $param['status'] = $request->param('status',0);

        /* 验证 */
        //$this->validateData($param,'Menu.list');

        /* 创建列表 */
        $ServiceMenu = new ServiceMenu();
        $result = $ServiceMenu->status($param);
        return Basic::json($result);
    }


    /**
     *  删除菜单
    */
    public function delete(Request $request)
    {

        $param['creator'] = $request->operator_id;
        $param['id'] = $request->param('id',null);

        /* 验证 */
        // $this->validateData($param,'Menu.create');

        /* 创建菜单 */
        $ServiceMenu = new ServiceMenu();
        $result = $ServiceMenu->delete($param);
        return Basic::json($result);
    }

}
